package com.rc.saas.tenant.mq;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.rc.saas.tenant.common.mq.MqConfig;
import com.rc.saas.tenant.common.mq.MqProducer;
import com.rc.saas.tenant.vo.log.TenantOperateLog;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;

/**
 * Created by sven on 2018-06-16
 */
@Component
public class TenantOperateLogAssemble {
    private static Logger logger = LogManager.getLogger(TenantOperateLogAssemble.class);
    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS");

    @Autowired
    private MqProducer mqProducer;

    public void assembleTenantOperateLog(TenantOperateLog log) {
        //推送日志消息
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            String msg = objectMapper.writeValueAsString(log);
            mqProducer.send(MqConfig.LOG_TENANT_OPERATE, msg);
        } catch (Exception e) {
            logger.error("推送日志消息报错", e);
        }
    }
}
